<?php
class ConexionBD {	
    private $servidor="190.27.248.70";
    private $puerto="5432";
    private $baseDatos="ServiPortuarios";
    private $usuario="postgres";
    private $contrasena="123456";
    
    private static $conexion;
    private $link;
    private $isOpen;

        

//--------------constructores-----------//
private function __construct(){  	//---definir los parametros
}

//-------------metodos de la clase-------//

public static function get(){   
	if(!isset(self::$conexion))
	    self::$conexion = new ConexionBD();
return self::$conexion;
}

public function conectarse(){	//  este metodo me permite conectarma a la base de datos

    if (!($this->link=pg_connect("host=" . $this->servidor . " port=" . $this->puerto . " dbname=" . $this->baseDatos .  " user=" . $this->usuario . " password=" . $this->contrasena)))
    { 
        echo json_encode(array("ERROR"=>"Error conectando a la base de datos."));  
        exit(); 
    }
    $this->isOpen=true;
    return $this->link;
} 

public function desconectarse(){	 //	cierra la conexion 
    if($this->isOpen) {
        pg_close($this->link); 
        $this->isOpen=false;
    }     
}
}
?>